package com.view.impl;

import com.dao.AccountDao;
import com.dao.impl.AccountDaoImpl;
import com.util.ReturnLevel;
import com.view.LoginView;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.util.Read.getIn;

public class AccountView extends LoginView {
    AccountDao accountDao = new AccountDaoImpl();

    public void insert() {
        System.out.println("请输入收入：");
        String ain = getIn().next();
        System.out.println("请输入支出：");
        String aout = getIn().next();

        System.out.println("请输入备注：");
        String ainfo = getIn().next();
        String aid = getInfo().get("a_id").toString();
        System.out.println("请输入日期（默认今天请输入1）：");
        String adate = getIn().next();
        if (adate.equals("1")) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date today = new Date(System.currentTimeMillis());
            adate = simpleDateFormat.format(today);
        }
        int r = accountDao.ainsert(ain, aout, ainfo, aid, adate);
        if (r > 0) {
            System.out.println("记账成功！");
        } else {
            System.out.println("记账失败，请重新记账！");
        }
        ReturnLevel.returnLevel();
    }
}
